pagination: activate page items with Space key#304
Open
SlimDumbledodge wants to merge 3 commits into
Open
Conversation
* Fixes page items not being activated by the "Space" key when focused via keyboard navigation. (closes inveniosoftware#295) * Page items are rendered by semantic-ui-react as anchors without href, with keyboard activation wired up manually for "Enter" only. Per the ARIA APG button pattern, elements behaving as buttons must be activatable with both "Enter" and "Space". * Adds a custom pageItem render function that invokes the injected onClick on "Space" keydown, prevents the default page scroll, and adds role="button" for assistive technologies.
* Fixes page items not being activated by the "Space" key when focused via keyboard navigation. (closes inveniosoftware#295) * Page items are rendered by semantic-ui-react as anchors without href, with keyboard activation wired up manually for "Enter" only. Per the ARIA APG button pattern, elements behaving as buttons must be activatable with both "Enter" and "Space". * Adds a custom pageItem render function that invokes the injected onClick on "Space" keydown, prevents the default page scroll, and adds role="button" for assistive technologies.
…imDumbledodge/react-searchkit into fix-pagination-space-key-a11y
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
❤️ Thank you for your contribution!
Description
Fixes #295
Root cause
Pagination page items are rendered by semantic-ui-react's
Paginationas anchors withouthrefand without an explicitrole:An anchor without
hrefhas no native keyboard activation, so semantic-ui-react makes it focusable withtabindex="0"and wires up keyboard activation manually inPaginationItem. However, only "Enter" is handled:Since these items behave as buttons (they trigger an action rather than navigate to a URL), the ARIA APG button pattern applies: they should be activatable with both "Enter" and "Space".
Fix
The root cause lives in semantic-ui-react, but it can be remediated on the react-searchkit side. This PR passes a custom render function to the
pageItemshorthand that:keydownby invoking the sameonClickthat semantic-ui-react injects into the item props, mirroring its existing "Enter" handlingpreventDefault()to avoid the default page scroll on "Space"role="button"so the announced semantics match the behavior for assistive technologiesMouse and "Enter" activation are unchanged.
Scope
The fix is intentionally scoped to page items, as reported in the issue. The first/prev/next/last arrow items share the same underlying limitation, but customizing them through the shorthand render function drops their default content (icons), so extending the fix to them would require rebuilding those defaults. Happy to address that in a follow-up if there is interest.
Note: using an item shorthand render function triggers a semantic-ui-react v3 deprecation warning in the test output. v3 was never released, this repo pins v2, and there is no alternative API to customize pagination items.
How to verify
docker-compose upinsrc/demos/opensearch/docker, load the demo data,npm start)Checklist
Ticks in all boxes and 🟢 on all GitHub actions status checks are required to merge:
Frontend
Reminder
By using GitHub, you have already agreed to the GitHub’s Terms of Service including that: